package string;

/**
 * java.lang.StringBuilder
 * java为了解决修改字符串的性能问题专门提供的字符串修改API
 *
 * StringBuilder内部维护一个可变的char数组，并且提供了便于修改字符串的相关方法：
 * 增删
 *
 */




public class StringBuilderDemo1 {
    public static void main(String[] args) {

        String str = "好好学习Java";

        //默认无参构造器创建时，StringBuilder内部表示一个空字符串：“”





        StringBuffer builder = new StringBuffer(str);
        System.out.println("str:"+str);
        System.out.println("builder:"+builder);





        builder.append(",为了找个好工作！");
        System.out.println("builder:"+builder);




        builder.replace(9,16,"就是为了改变世界!");
        System.out.println("builder:"+builder);



        builder.delete(0,8);
        System.out.println("builder:"+builder);





        builder.insert(0,"用力活着");
        System.out.println("builder:"+builder);




        builder.reverse();
        System.out.println("builder:"+builder);







        String str2 = builder.toString();
        System.out.println("str2:"+str2);
















//        builder.replace(9,16,"就是为了改变世界");
//        System.out.println("builder:"+builder);






















    }
}
